import Binary from '../constdata/binaryTree';
type BinaryType = {
  val: string;
  left?: BinaryType;
  right?: BinaryType;
};
const BFS = (root:BinaryType) => {
  // 借助队列实现二叉树的层序遍历
  const queue: Array<BinaryType> = [];
  // 添加对头
  queue.push(root);
  // 当队列不为空
  while (queue.length) {
    // 取出来队列第一个元素
    const top = queue[0];
    console.log(top.val);
    //
    if (top.left) queue.push(top.left);
    if (top.right) queue.push(top.right);
    // 遍历完毕弹出队头
    queue.shift();
  }
};

BFS(Binary);
